<%@ page language="java" contentType="text/html; charset=utf-8"%>
<%@ include file="/taglibs.jsp"%>
<html>
<head>
<title>IT管理后台</title>
<link rel="stylesheet" type="text/css" href="/js/themes/default/easyui.css">
<link rel="stylesheet" type="text/css" href="/js/themes/icon.css">
<script type="text/javascript" src="/js/jquery-1.4.4.min.js"></script>
<script type="text/javascript" src="/js/jquery.easyui.min.js"></script>
<script type="text/javascript" src="/js/easyui_validatebox.js"></script>
<script type="text/javascript" src="/js/locale/easyui-lang-zh_CN.js"></script>
<script src="/js/print.js" type="text/javascript"></script>
<style type="text/css">

td {
	font-size: 13px;
	
}
table.ttb{border-left:solid 1px #99bbe8;border-top: solid 1px #99bbe8;}
table.ttb td{word-break: break-all; word-wrap:break-word;vertical-align: top; padding-left:8px; border-right: solid 1px #99bbe8;border-bottom: solid 1px #99bbe8; line-height: 24px; font-size: 12px;}
.bg001{font-weight: bold; color: #333; background-color: #edf4fc}
</style>
	<script>
		$(function(){
			$('#tab').datagrid({
				title:'员工设备信息',
				iconCls:'icon-save',
				nowrap: false,
				striped: true,
				pageSize:20,
				sortName:"id",
				sortOrder:"desc",
				pageList:[10,20,30,40,50],
				url:'/itmanager/ygsb/json',
				remoteSort: false,
				idField:'id',
				frozenColumns:[[
	                	{field:'ck',checkbox:true},
	                	{title:'员工编号',field:"ygbh",width:80},
						{title:'员工姓名',field:"xm",width:80,formatter:
					    	 function(value,rowData,rowIndex){
						    	return "<span style='cursor: hand;color: green;' onclick='showYg("+rowData.ygid+")'>"+value+"</span>";
					    	 }
					    },
						{title:'设备编号',field:"sbbh",width:80},
						{title:'设备名称',field:"sbmc",width:120,formatter:
					    	 function(value,rowData,rowIndex){
					    		return "<span style='cursor: hand;color: green;' onclick='showSb("+rowData.sbid+")'>"+value+"</span>";
				    	 	}
						},
						{title:'设备状态',field:"zt",width:80,formatter:
					    	 function(value,rowData,rowIndex){
					    	 if(value == "0"){
					    		 return "<font color='red'>使用</font>";
					    	 }
					    	 else if(value == "1"){
					    		 return "<font color='red'>闲置</font>";
					    	 }
					    	 else if(value == "2"){
					    		 return "<font color='red'>借出</font>";
					    	 }else if(value == "3"){
					    		 return "<font color='red'>待修</font>";
					    	 }else if(value == "4"){
					    		 return "<font color='red'>已坏</font>";
					    	 }
				     		},
					     	editor:{
								type:'combobox',
								options:{
									valueField:'value',
									textField:'text',
									data:[{"text":"使用","value":"0"},{"text":"闲置","value":"1"},{"text":"借出","value":"2"},{"text":"待修","value":"3"},{"text":"已坏","value":"4"}],
									required:true
									}
								}
						}
	                ]],
				columns:[
					[
						{title:'关联时间',field:"glsj",width:100,
							editor:{
								type:'datebox',
								options:{
									required:true
									}
								}
						}
					]
				],
				fit:true,
				border:false,
				pagination:true,
				rownumbers:true,
				toolbar:[{
					id:"13",
					text:'添加关联',
					disabled:true,
					iconCls:'icon-add',
					handler:function(){
						ygsbadd.window({
							onBeforeOpen:function(){
								ygsbaddform.form('clear');
								clearSel($("#ygid-add")[0]);
								clearSel($("#sbid-add")[0]);
								$.ajax({
									   type: "get",
									   url: "/itmanager/common/cllx",
									   data: "lx=bm",
									   success: function(msg){
										   var bmm = $("#bm-add")[0];  //把jquery对象转成dom对象使用
										   clearSel(bmm); //清空
										   msg=$.parseJSON(msg);
										   var value1="";
										   var text1="--请选择部门--";
										   var option1=new Option(text1,value1);
										   bmm.options.add(option1);
										   $.each(msg, function(i, b) {
												var value = b.id;
												var text = b.clmc;
												var option = new Option(text, value);
												bmm.options.add(option);
											});
									   }
								});
								$.ajax({
									   type: "get",
									   url: "/itmanager/sbfl/all",
									   success: function(msg){
										   var sbm = $("#sbflid-add")[0];  //把jquery对象转成dom对象使用
										   clearSel(sbm); //清空
										   msg=$.parseJSON(msg);
										   var value1="";
										   var text1="--请选择设备分类--";
										   var option1=new Option(text1,value1);
										   sbm.options.add(option1);
										   $.each(msg, function(i, b) {
												var value = b.id;
												var text = b.sbflmc;
												var option = new Option(text, value);
												sbm.options.add(option);
											});
									   }
								});
							}
						});
						ygsbadd.window("open");
					}
				},'-',{
					id:'3',
					text:'删除',
					disabled:true,
					iconCls:'icon-remove',
					handler:function(){
						deleteYgsb();
					}
				},'-',{
					id:'12',
					text:'修改状态',
					disabled:true,
					iconCls:'icon-redo',
					handler:function(){
						$('#tab').datagrid('acceptChanges');
					}
				},'-',{
					id:'7',
					text:'取消',
					disabled:true,
					iconCls:'icon-undo',
					handler:function(){
						$('#tab').datagrid('rejectChanges');
					}
				},'-',{
					id:'9',
					text:'打印',
					disabled:true,
					iconCls:'icon-print',
					handler:function(){
						startPrint($(".datagrid-view")[0]);
					}
				}],
				onAfterEdit:function(rowIndex, rowData, changes){
					$.ajax({
							type: "post",
							url: "/itmanager/ygsb/edit",
							data: "sbid="+rowData.sbid+"&zt="+rowData.zt+"&glsj="+rowData.glsj+"&id="+rowData.id,
							success: function(msg){
								if (msg=='success'){  
									$.messager.show({
										title:'信息提示',
										msg:'修改成功！',
										timeout:2000,
										showType:'slide'
									});
						        	$("#tab").datagrid("reload");
						         } else if(msg=='error'){
						           	$.messager.alert('信息提示','修改失败！','error');
						         }
							}
					});
				},
				onDblClickRow:function(rowIndex, rowData){
					$('#tab').datagrid('endEdit', rowIndex);
					$('#tab').datagrid('beginEdit', rowIndex);
					
				},
				onClickRow:function(rowIndex, rowData){
					var row=$('#tab').datagrid('getSelected');
					var index=$('#tab').datagrid('getRowIndex',row);
					if (index == -1){
						$('#tab').datagrid('selectRow',rowIndex);
					}else{
						$('#tab').datagrid('unselectRow',rowIndex);
					}
				}
			});
			
			 $("#tab").datagrid("getPager").pagination({
				   onSelectPage:function(){
					  $("#tab").datagrid("clearSelections");
					  var queryParams = $.extend({},$("#tab").datagrid("options").queryParams,
							  {spsbmc:$("#sbmc-search").val(),spsbbh:$("#sbbh-search").val(),spygbh:$("#ygbh-search").val(),spxm:$("#xm-search").val(),spbfjlsj:$("#bfjlsj-search").datebox("getValue"),spafjlsj:$("#afjlsj-search").datebox("getValue")}); 
					  $("#tab").datagrid("reload",queryParams);
				   }
			  });
			 
			
			 
			 yg = $('#yg-window').window({
					modal: true,
					maximizable:false,
					minimizable:false,
					collapsible:false,
					closed:true
				});
			sb = $('#sb-window').window({
				modal: true,
				maximizable:false,
				minimizable:false,
				collapsible:false,
				closed:true
			});
			ygsbadd = $('#ygsb-add').window({
				modal: true,
				maximizable:false,
				minimizable:false,
				collapsible:false,
				closed:true
			});
			ygsbaddform=ygsbadd.find("form");
			
			 var ens='${param.en}';
			 var en=ens.split(":");
			 for(var i=0;i<en.length;i++){
				 if(en[i] != "" && en[i] != null){
				 	$("#"+en[i]).linkbutton('enable');
				 }
			 }
			
		});
		
		var find = function(){
			$("#tab").datagrid("clearSelections");
			var queryParams = $.extend({},$("#tab").datagrid("options").queryParams,
					{spsbmc:$("#sbmc-search").val(),spsbbh:$("#sbbh-search").val(),spygbh:$("#ygbh-search").val(),spxm:$("#xm-search").val(),spbfjlsj:$("#bfjlsj-search").datebox("getValue"),spafjlsj:$("#afjlsj-search").datebox("getValue")}); 
			$("#tab").datagrid("getPager").pagination({pageNumber:1});
			$("#tab").datagrid("reload",queryParams);
		}
		
		
		var showYg=function(ygid){
			$.ajax({
		 		type:"get",
		 		url:"/itmanager/yg/show",
		 		cache: false,
		 		data:"id="+ygid,
		 		success:function(data){
		 		 	yg.window("open");
		 		 	data=$.parseJSON(data);
					mtext("#yg-ygbh",data.ygbh);
					mtext("#yg-bm",data.bmmc);
					mtext("#yg-zw",data.zwmc);
					mtext("#yg-xm",data.xm);
					mtext("#yg-lxdh",data.lxdh);
					mtext("#yg-nl",data.nl);
		 		}
		 	});
		};
		var showSb=function(sbid){
			$.ajax({
		 		type:"get",
		 		url:"/itmanager/sb/show",
		 		data:"id="+sbid,
		 		success:function(data){
		 		 	sb.window("open");
		 		 	data=$.parseJSON(data);
					mtext("#sb-sbbh",data.sbbh);
					mtext("#sb-sbfl",data.sbflmc);
					mtext("#sb-sbmc",data.sbmc);
					mtext("#sb-jhsj",data.jhsj);
					mtext("#sb-sbsx",data.sbsx);
					var zt=data.zt;
					if(zt=='0'){
						mtext("#sb-zt","使用");
					}else if(zt=='1'){
						mtext("#sb-zt","闲置");
					}else if(zt=='2'){
						mtext("#sb-zt","借出");
					}else if(zt=='3'){
						mtext("#sb-zt","待修");
					}else if(zt=='4'){
						mtext("#sb-zt","已坏");
					}
		 		}
		 	});
		};
		
		function createYgsb(){
			ygsbaddform.form('submit', {  
				  url:ygsbaddform.action,
				  onSubmit:function(){
				        return $(this).form('validate');
				    },
				  success:function(data){
				          if (data=='success'){  
				        	  	$.messager.alert('信息提示','添加成功！','right');  
				                ygsbadd.window('close');  
				                var queryParams = $.extend({},$("#tab").datagrid("options").queryParams);
					 			$("#tab").datagrid("reload",queryParams);
				            } else if(data=='error'){
				            	$.messager.alert('信息提示','添加失败！','error');
				            }
				     }  
			}); 
		}
		
		function textsx(id){
			$.ajax({
				type: "get",
				url: "/itmanager/common/clid",
				data: "id="+id,
				success: function(msg){
					var data=$.parseJSON(msg);
					var bhsx=data.bhsx;
					if(bhsx != undefined && bhsx!=null){
						var bh=bhsx.split("&");
						$("#add-textsx").html("");
						for(i=0;i<bh.length;i++){
							$("#add-textsx").append(bh[i]);
						}
					}
				}
			});
		}
		
		function mtext(target,text){
			$(target).html("&nbsp;");
			$(target).html(text);
		}
		
		function clearSel(oSelect) {
			while (oSelect.childNodes.length > 0) {
				oSelect.removeChild(oSelect.childNodes[0]);
			}

		}
		
		function closeYgsbadd(){
			ygsbadd.window('close');
		}
		
		function getYgList(bmid){
			$.ajax({
				type:"post",
				url:"/itmanager/yg/bmyg",
				data:"bm="+bmid,
				success:function(data){
					var ygl=$("#ygid-add")[0];
					clearSel(ygl);
					data=$.parseJSON(data);
					$.each(data,function(i,yg){
						var value=yg.id;
						var text="("+yg.ygbh+")-"+yg.xm;
						var option=new Option(text,value);
						ygl.options.add(option);
					});
				}
			});
		}
		
		function getSbflList(sbflid){
			$.ajax({
				type:"post",
				url:"/itmanager/sb/sbfllist",
				data:"sbflid="+sbflid,
				success:function(data){
					var sbl=$("#sbid-add")[0];
					clearSel(sbl);
					data=$.parseJSON(data);
					$.each(data,function(i,sb){
						var value=sb.id;
						var text="("+sb.sbbh+")-"+sb.sbmc;
						var option=new Option(text,value);
						sbl.options.add(option);
					});
				}
			});
		}
		
		function showTheSb(sbid){
			$("#show-sbtext").text("");
			if(sbid!=""){
				$.ajax({
					type:"get",
					url:"/itmanager/sb/show",
					data:"id="+sbid,
					cache:false,
					success:function(data){
						data=$.parseJSON(data);
						var st="";
						var zt=data.zt;
						if(zt=='0'){
							st="使用";
						}else if(zt=='1'){
							st="闲置";
						}else if(zt=='2'){
							st="借出";
						}else if(zt=='3'){
							st="待修";
						}else if(zt=='4'){
							st="已坏";
						}
						$("#show-sbtext").html("设备编号："+data.sbbh+
								" 设备名称："+data.sbmc+" 进货时间："+data.jhsj+" <br/>设备属性："+data.sbsx
								+" <br/>设备状态：<font color='red'>"+st+"</font>");
					}
				});
			}
		}
		
		var deleteYgsb = function(){
			var rows = $("#tab").datagrid("getSelections");
			var length = rows.length;
			if(length == 0){
				$.messager.alert("友情提示","<br/><b>请先选择记录！</b>","error");
				return false;
			}
			var ids = [];
			for(var i=0;i<length;i++){
				ids.push(rows[i].id);
			}
			ids.join(",");
			$.messager.confirm("友情提示","<br/><b>确定删除记录？</b>",function(result){
				if(result){
					$.ajax({
				 		type:"post",
				 		url:"/itmanager/ygsb/delete",
				 		data:"ids="+ids,
				 		success:function(data){
				 			if(data=='success'){
				 		 		var queryParams = $.extend({},$("#tab").datagrid("options").queryParams);
				 				$("#tab").datagrid("reload",queryParams);
				 				$("#tab").datagrid("clearSelections");
				 			}else if(data=='error'){
				 				$.messager.alert("友情提示","<br/><b>删除记录出错！</b>","error");
				 			}
				 		}
				 	});
				}
			});
		} 
		
		
		
		/* var sh = function(param){
			var rows = $("#tab").datagrid("getSelections");
			var length = rows.length;
			if(length == 0){
				$.messager.alert("友情提示","<br/><b>请先选择记录！</b>","error");
				return false;
			}
			var ids = [];
			for(var i=0;i<length;i++){
				ids.push(rows[i].id);
			}
			ids.join(",");
		 	$.ajax({
		 		type:"post",
		 		url:"/manager/yg/sh",
		 		data:"shqk="+param+"&ids="+ids,
		 		success:function(data){
		 		 	var queryParams = $.extend({},$("#tab").datagrid("options").queryParams);
		 			$("#tab").datagrid("reload",queryParams);
		 			$("#tab").datagrid("clearSelections");
		 		}
		 	});
		} */
		
	</script>
</head>
<body class="easyui-layout">
	<div region="north" border="false" style="height:90px;" iconCls="icon-search" title="查询条件">
		<table width="100%" height="100%" style="background-color:#E0ECFF ">
			<thead>
				<tr>
					<td align="center">员工编号：</td>
					<td><input type="text" name="spygbh" id="ygbh-search" value="${smap.spygbh }"></td>
					<td align="center">员工姓名：</td>
					<td><input type="text" name="spxm" id="xm-search" value="${smap.spxm }"></td>
					<td align="center">设备编号：</td>
					<td><input type="text" name="spsbbh" id="sbbh-search" value="${smap.spsbbh }"></td>
					<td align="center">设备名称：</td>
					<td><input type="text" name="spsbmc" id="sbmc-search" value="${smap.spsbmc }"></td>
					
				</tr>
				<tr><td align="center">查询时间：</td>
					<td nowrap="nowrap" colspan="6">
						<input name="spbfjlsj" id="bfjlsj-search" class="easyui-datebox"/>到<input name="spafjlsj" id="afjlsj-search" class="easyui-datebox"/>
					</td>
					<td><a id="4" disabled="true" class="easyui-linkbutton" iconCls="icon-search" onclick="find()">查询</a></td>
				</tr>
			</thead>
		</table>
	</div>
	<div id="center" region="center">
		<table id="tab"></table>
	</div>
	
	<div id="sb-window" title="查看设备详情" style="width:500px;">
				
		<table class="ttb" border="0" cellspacing="0" cellpadding="0" width="100%">
							<tr>
								<td nowrap="nowrap" class="bg001" class="bg001">设备编号：</td>
								<td nowrap="nowrap" id="sb-sbbh">&nbsp;</td>
								<td nowrap="nowrap" class="bg001" class="bg001">设备类型：</td>
								<td nowrap="nowrap" id="sb-sbfl">&nbsp;</td>
								<td nowrap="nowrap" class="bg001">设备名称：</td>
								<td nowrap="nowrap" id="sb-sbmc">&nbsp;</td>
							</tr>
							<tr>
								<td nowrap="nowrap" class="bg001">设备属性：</td>
								<td id="sb-sbsx" colspan="7"></td>
							</tr>
							<tr>
								<td nowrap="nowrap" class="bg001">设备状态：</td>
								<td nowrap="nowrap" id="sb-zt" style="color:red;"></td>
								<td nowrap="nowrap" class="bg001">进货时间：</td>
								<td nowrap="nowrap" id="sb-jhsj">&nbsp;</td>
							</tr>		
							
		</table>
	</div>
	
	<div id="ygsb-add" title="添加设备" style="width:350px;height:300px;">
				<div style="text-align: center;padding-top: 5px;">
					<form method="post" action="/itmanager/ygsb/add">
						<table>
							<tr>
								<td>所属部门：</td>
								<td>
									<select name="bm" id="bm-add" style="width:150px;" onchange="getYgList(this.value)">
									</select>
								</td>
							</tr>
							
							<tr>
								<td>员工：</td>
								<td>
									<select name="ygid" id="ygid-add" style="width:150px;" required="true"></select>
								</td>
							</tr>
							<tr>
								<td>设备分类：</td>
								<td><select name="sbflid" id="sbflid-add" style="width:150px;" onchange="getSbflList(this.value)"></select></td>
							</tr>
							<tr>
								<td>设备：</td>
								<td>
									<select name="sbid" id="sbid-add" style="width:150px;" required="true" onfocus="showTheSb(this.value)" onchange="this.onfocus()">
									</select>
								</td>
							</tr>
							<tr>
								<td>关联时间：</td>
								<td>
									<input name="glsj" id="glsj-add" style="width:150px;" required="true" class="easyui-datebox"/>
								</td>
							</tr>
						</table>
						<div id="show-sbtext"></div>
					</form>
				</div>
				<div style="text-align:center;">
					
					<a href="javascript:void(0)" onclick="createYgsb()" class="easyui-linkbutton" id="sb-add-button" icon="icon-save">添加</a>
					<a href="javascript:void(0)" onclick="closeYgsbadd()" class="easyui-linkbutton" id="sb-cancel-button" icon="icon-cancel">取消</a>
				</div>
		</div>
		
		
	<div id="yg-window" title="查看员工详情" style="width:500px;">
				
		<table class="ttb" border="0" cellspacing="0" cellpadding="0" width="100%">
							<tr>
								<td nowrap="nowrap" class="bg001" class="bg001">员工编号：</td>
								<td id="yg-ygbh">&nbsp;</td>
								<td nowrap="nowrap" class="bg001" class="bg001">所属部门：</td>
								<td id="yg-bm">&nbsp;</td>
								<td nowrap="nowrap" class="bg001">职位：</td>
								<td id="yg-zw">&nbsp;</td>
								<td nowrap="nowrap" class="bg001">姓名：</td>
								<td id="yg-xm">&nbsp;</td>
							</tr>
							<tr>
								<td nowrap="nowrap" class="bg001">联系电话：</td>
								<td id="yg-lxdh">&nbsp;</td>
								<td nowrap="nowrap" class="bg001">年龄：</td>
								<td id="yg-nl" colspan="5">&nbsp;</td>
							</tr>
									
		</table>
					
	</div>
		
		

</body>
</html>